<template>
	<view class="box">
		<!-- input -->
		<view class="f_header sticky-box">
			 <view class="search-block">
				  <view class="search-ico-wapper">
					 <image src="../../static/img/yuncang/home_search.png" class="search-ico" mode=""></image>
				  </view>
				  
				  <input type="text" placeholder="点击输入商品名称" class="search-text" maxlength="10" v-model="val" @change="changeBtn(val)"/>
				  
				  <view class="search-ico-wapper1">
					 <image src="" class="search-ico-1" mode=""></image>
				 </view>
			 </view>
		</view>
		
		<!-- 列表 -->
		<!-- <view class="guess-section">
			<view class="guess-item" v-for="(item, index) in goodsList" :key="index" @click="navToDetailPage(item)">
				<view class="image-wrapper">
					<image :src="item.goods.picUrl" mode="aspectFill"></image>
				</view>
				<text class="title clamp">{{item.goods.name}}</text>
				<view class="price_mon">
					<view>
						<text class="price">￥{{item.goods.retailPrice}}</text>
						<text class="price_del">￥{{item.goods.counterPrice}}</text>
					</view>
					<text class="Sold">已售{{item.goods.salesNum}}{{item.goods.unit}}</text>
				</view>
			</view>
		</view> -->
		<!-- 订单列表 -->
		<view class="order-item">
			
			<view v-for="(goodsItem, goodsIndex) in goodsList" :key="goodsIndex">
				<view class="goods-box-single" @click="navToDetailPage(goodsItem)">
					<image class="goods-img" :src="goodsItem.goods.picUrl" mode="aspectFill"></image>
					<view class="right">
						
						<text class="title clamp">{{goodsItem.goods.name}}</text>
						<text class="attr-box">{{goodsItem.goods.brief}}</text>
						
						<view style="display: flex;justify-content: space-between;">
							<text class="yunNum">云库存{{goodsItem.goodsStock}}盒</text>
							<text class="price">{{goodsItem.goods.retailPrice}}</text>
						</view>
					</view>
				</view>
				
				<view class="action-box b-t">
					<button class="action-btn" @click="navToDetailPage(goodsItem)">去提货</button>
					<button class="action-btn recom" @click="navToPage()">查看明细</button>
				</view>
			</view>
			
		</view>
		
		
		
		<!--加载loadding-->
		<tui-loadmore v-if="loadding" :index="total" type="primary"></tui-loadmore>
		<tui-nomore v-if="!pullUpOn"></tui-nomore>
		<!--加载loadding-->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				val:"",
				goodsList: [],			//商品列表
				total:"",				//商品数	
				page:"1",				//几页
				limit:"10",				//一页十条
				pages:"",				//一共多少页
				loadding: false,		//加载
				pullUpOn: true, 		//没有数据
				goodsId:"",
			};
		},

		onLoad() {
			this.loadData();
		},
		
		methods: {
			changeBtn(val){
				console.log(val)
				this.tui.request(
					'/app/cloud/list',
					'GET', 
					{
						keywords:val
					},
					false,
					false,
					false,
				).then(res => {
					if(res.errno == 0){
						this.total = res.data.total;
						this.pages = res.data.pages;
						this.pages = res.data.pages;
						this.goodsId = res.data.list[0].goodsId;
						
						let worksList = res.data.list;
						worksList.forEach(item => {
							this.goodsList.push(item);
						});						
					}
				}).catch(err => {
					console.log(err)
				});
			},
			
			// 加载商品 ，带下拉刷新和上滑加载
			loadData() {
				this.tui.request(
					'/app/cloud/list',
					'GET', 
					{
						page:this.page,
						limit:this.limit,
					},
					false,
					false,
					false,
				).then(res => {
					if(res.errno == 0){
						this.total = res.data.total;
						this.pages = res.data.pages;
						
						let worksList = res.data.list;
						worksList.forEach(item => {
							this.goodsList.push(item);
						});						
					}
				}).catch(err => {
					console.log(err)
				});
				
			},
			
			// 上拉加载
			onReachBottom: function() {
				if (!this.pullUpOn) {
					return;
				}
				this.loadding = true;
				if (this.page == this.pages) {
					this.loadding = false;
					this.pullUpOn = false
				} else {
					++this.page;
					this.loadData();
					this.loadding = false
				}
			},

			// 详情页
			navToDetailPage(item) {
				let id = "";
				if(item.goodsId){
					id = item.goodsId
				}
				
				uni.navigateTo({
					url: `/pages/product/product?id=${id}&orderType=4`
				})
			},
			// 明细
			navToPage(){
				uni.navigateTo({
					url: `/pages/order/order?id=5&state=0&orderState=0`
				})
			}
		}
	}
</script>

<style lang="scss">
	.box{
		height: 100%;
		background: #FAFAFA;
	}
	
	
	/* 搜索框 */
	.f_header {
		display: flex;
		align-items: center;
		height: 45px;
		background: #FAFAFA;
	}
	.search-block{
	    display: flex;
	    flex-direction: row;
	    padding-left: 30upx;
	    position: relative;
	    color: #666666;
		border: 1px solid #eeeeee;
		border-radius: 30px;
		margin: 0 auto;
	}
	.search-ico-wapper{
	    background-color: #FFFFFF;
	    display: flex;
	    flex-direction:column;
	    justify-content: center;
	    padding: 0upx 10upx 0upx 20upx;
	    border-bottom-left-radius:18px;
	    border-top-left-radius: 18px;
	}
	.search-ico-wapper1{
	    background-color: #FFFFFF;
	    display: flex;
	    flex-direction:column;
	    justify-content: center;
	    padding: 0upx 40upx 0upx 0upx;
	    border-bottom-right-radius:18px;
	    border-top-right-radius: 18px;
	}
	.search-ico, .search-ico-1{
	     width: 30upx;
	     height: 30upx;
	}
	.search-text{
	     font-size: 14px;
	     background-color: #FFFFFF;
	     height: 60upx;
	     width: 400upx;
	}
	.shadow{
	    width: 638upx;
	    height: 60upx;
	    border-radius:18px;
	    -moz-box-shadow:0 0 10px #e6e6e6;
	    -webkit-box-shadow:0 0 10px #e6e6e6;
	    box-shadow:0 0 10px #e6e6e6;
	    position: relative;
	    top: -90upx;
	    left: 60upx;
	}
	/*吸顶*/
	.sticky-box {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		position: -webkit-sticky;
		/* #endif */
		position: sticky;
		top: var(--window-top);
		z-index: 99;
		flex-direction: row;
	}
	
	/* 商品列表 */
	.guess-section {
		display: flex;
		flex-wrap: wrap;
		padding: 0 30upx;
		background: #fff;
	
		.guess-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;
	
			&:nth-child(2n+1) {
				margin-right: 4%;
			}
		}
	
		.image-wrapper {
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;
	
			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
	
		.title {
			font-size: $font-lg;
			color: $font-color-dark;
			line-height: 80upx;
		}
	
		.price_mon {
			display: flex;
			align-items: center;
			justify-content: space-between;
	
			.price {
				font-size: 16px;
				color: #D14798;
				line-height: 1;
				font-weight: 500;
			}
	
			.price_del {
				color: #ccc;
				font-size: 12px;
				text-decoration: line-through;
			}
	
			.Sold {
				color: #ccc;
				font-size: 12px;
			}
		}
	}
	
	
	
	
	.order-item {
		display: flex;
		flex-direction: column;
		padding-left: 30upx;
		background: #fff;
		margin-top: 16upx;
	
		.i-top {
			display: flex;
			align-items: center;
			height: 80upx;
			padding-right: 30upx;
			font-size: $font-base;
			color: #333333;
			position: relative;
	
			.time {
				flex: 1;
				color: #333333;
			}
	
			.state {
				color: #FF0000;
			}
	
			.del-btn {
				padding: 10upx 0 10upx 36upx;
				font-size: $font-lg;
				color: $font-color-light;
				position: relative;
	
				&:after {
					content: '';
					width: 0;
					height: 30upx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20upx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
	
		/* 多条商品 */
		.goods-box {
			height: 160upx;
			padding: 20upx 0;
			white-space: nowrap;
	
			.goods-item {
				width: 120upx;
				height: 120upx;
				display: inline-block;
				margin-right: 24upx;
			}
	
			.goods-img {
				display: block;
				width: 100%;
				height: 100%;
			}
		}
	
		/* 单条商品 */
		.goods-box-single {
			display: flex;
			padding: 20upx 0;
	
			.goods-img {
				display: block;
				width: 120upx;
				height: 120upx;
			}
	
			.right {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 30upx 0 24upx;
				overflow: hidden;
	
				.title {
					font-size: $font-base + 2upx;
					color: $font-color-dark;
					line-height: 1;
				}
	
				.attr-box {
					font-size: $font-sm + 2upx;
					color: $font-color-light;
					// padding: 10upx 12upx;
					padding-top: 12upx;
				}
	
				.number {
					font-size: 12px;
					color: #999999;
					text-align: right;
	
					&:before {
						content: '￥';
						font-size: $font-sm;
						margin: 0 2upx 0 8upx;
					}
				}
	
				.price {
					font-size: $font-base + 2upx;
					color: #D14798;
					text-align: right;
	
					&:before {
						content: '￥';
						font-size: $font-sm;
						margin: 0 2upx 0 8upx;
					}
				}
			}
		}
	
		.price-box {
			display: flex;
			justify-content: flex-end;
			align-items: baseline;
			padding: 20upx 30upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
	
			.num {
				margin: 0 8upx;
				color: $font-color-dark;
			}
	
			.price {
				font-size: $font-lg;
				color: $font-color-dark;
	
				&:before {
					content: '￥';
					font-size: $font-sm;
					margin: 0 2upx 0 8upx;
				}
			}
		}
		.yunNum{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #999999;
			line-height: 40upx;
		}
	
		.action-box {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 100upx;
			position: relative;
			padding-right: 30upx;
		}
	
		.action-btn {
			width: 160upx;
			height: 60upx;
			margin: 0;
			margin-left: 24upx;
			padding: 0;
			text-align: center;
			line-height: 60upx;
			font-size: $font-sm + 2upx;
			color: $font-color-dark;
			background: #fff;
			border-radius: 100px;
	
			&:after {
				border-radius: 100px;
			}
		}
	}
	
	
</style>
